package com.content.management.domain.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.content.management.domain.entity.BusPublishContent;
import com.content.management.domain.entity.DictionaryData;
import com.content.management.util.DateHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;

/**
 * @author xinghu
 * @version 1.0
 * @date 2020/4/4 4:36 下午
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "内容发布返回信息", description = "发布内容")
public class PublishContentVo {

	@ApiModelProperty(value = "主键id")
	private Long id;

	@ApiModelProperty(value = "发布时间")
	private LocalDateTime publishTime;

	@ApiModelProperty(value = "发布状态：0：已发布；1：未发布")
	private String publishStatus;

	@ApiModelProperty(value = "内容主题")
	private String contentTopic;

	@ApiModelProperty(value = "作者")
	private String contentAuthor;

	@ApiModelProperty(value = "发布的具体类容")
	private String content;

	@ApiModelProperty(value = "面向的发布人群")
	private String publishCrowd;

	@ApiModelProperty(value = "发布类型")
	private String publishType;

	@ApiModelProperty(value = "所属分类")
	private String classification;

	@ApiModelProperty(value = "创建时间")
	@JSONField(format = DateHelper.DATE_TIME_FORMAT)
	private LocalDateTime createTime;

	public static PublishContentVo of(BusPublishContent content, Map<String, DictionaryData> mapData) {
		PublishContentVo vo = new PublishContentVo();
		BeanUtils.copyProperties(content, vo);
		vo.setPublishStatus(content.getPublishStatus().equals(0) ? "已发布" : "未发布");
		DictionaryData dictionaryData = mapData.get(content.getClassification());
		vo.setClassification(Objects.nonNull(dictionaryData) ? dictionaryData.getDictionaryData() : "");
		return vo;
	}
}
